<#include "/default/layout/account.htm"/> 
<@layout>
      <div class="block-center mt-xl wd-xl">
         <div class="panel panel-dark panel-flat">
            <div class="panel-body" id="registPage">
               <p class="text-center pv">快速注册新用户</p>
               <form id="inputForm" method="POST" action="${ctx}/user/register?redirect=${RequestParameters.redirect!}">
                  <div class="form-group has-feedback">
                     <input id="email" type="email" placeholder="输入邮箱地址" class="form-control" name="email" value="${email!}" required="required"/>                  
                     <span class="fa fa-envelope form-control-feedback text-muted"></span>
                  </div>
                  <div class="form-group has-feedback">
                     <input id="phone" type="text" placeholder="输入手机号码" class="form-control" name="phone"  value="${phone!}"  required="required"/>
                     <span class="fa fa-phone form-control-feedback text-muted"></span>
                  </div>
                
                  <div class="form-group has-feedback">
                     <input id="fullname" type="text" placeholder="请输入姓名" class="form-control" name="fullname"  value="${fullname!}"  required="required"/>
                     <span class="fa fa-user form-control-feedback text-muted"></span>
                  </div>
                  <div class="form-group has-feedback">
                     <input id="company" type="text" placeholder="请输入工作单位" class="form-control" name="company"  value="${company!}"  required="required"/>
                     <span class="fa fa-bank form-control-feedback text-muted"></span>
                  </div>
                  <div class="form-group has-feedback">
                     <input id="position" type="text" placeholder="请输入职位" class="form-control" name="position"  value="${position!}" />
                     <span class="fa fa-tag form-control-feedback text-muted"></span>
                  </div>
                  <div class="form-group has-feedback">
                     <input id="wechat" type="text" placeholder="请输入微信号" class="form-control" name="wechat"  value="${wechat!}" />
                     <span class="fa fa-wechat form-control-feedback text-muted"></span>
                  </div>
                  <div class="form-group has-feedback">
                     <input id="registerway" type="text" placeholder="请输入注册途径" class="form-control" name="registerway"  value="${registerway!}" />
                     <span class="fa fa-navicon form-control-feedback text-muted"></span>
                  </div>
                  
                  <div class="row form-group">
						  <div class="col-md-2 col-sm-4" >
						  	<input id="key" name="key" placeholder="6位数字" class="form-control" data-parsley-required-message="6位数字" data-parsley-type-message="6位数字" required="required" value="${key!}"/> 
						  </div>
						  <div class="col-md-2 col-sm-4" >
						  	<a id="sendphoneButton" onclick="sendphone();" class="btn btn-block btn-default">发送验证码</a>
						  </div>
				 </div>
                  <div class="form-group has-feedback">
                     <input id="password" type="password" placeholder="请输入6-16位字母数字组合" class="form-control" name="password"  value="${password!}"  required="required"/>
                     <span class="fa fa-lock form-control-feedback text-muted"></span>
                  </div>
                  <div class="form-group has-feedback">
                     <input id="confirmPwdCipher" type="password" placeholder="再次输入密码" class="form-control" name="confirmPwdCipher" value="${confirmPwdCipher!}"  required="required"/>
                     <span class="fa fa-lock form-control-feedback text-muted"></span>
                  </div>
                  <p class="text-center" style="color: red" id="message" >${message!}</p>
                  <button class="btn btn-block btn-primary mt-lg">创建账户</button>
               </form>
               <p></p>
               <a href="${ctx}/login?device=android&redirect=${RequestParameters.redirect!}" class="btn btn-block btn-default">返回登录</a>
            </div>
         </div>
         <div class="p-lg text-center">
         </div>
      </div>
   </div>
   	
	<script type='text/javascript' th:inline="javascript">
		function sendphone() {
			$("#sendphoneButton").text("正在发送中...");
			if($('#sendphoneButton').attr("disabled") != "disabled"){
				var redirect ='${redirect!}';
				var phone = $("#phone").val();
				$('#sendphoneButton').attr("disabled", true);
				$.ajax({                                               
					url: '/user/sentphone', 
					data:{'redirect':redirect,'phone':phone,'category':'register'},
					type: 'GET',
					contentType: "application/json;charset=UTF-8",		
					dataType: 'text',
					success: function(data){
						$("#message").text("");
						var resultData = $.parseJSON(data);
						if(resultData.code == 200 || resultData.status == 'success'){
							var t=200;//设定跳转的时间 
							var time = setInterval(
									function (){  
									    $("#sendphoneButton").text("验证码已发送 "+t+" 秒后重试"); // 显示倒计时 
									    t--; // 计数器递减 
									    if(t==0){ 
									    	clearInterval(time);
									    	$('#sendphoneButton').removeAttr("disabled");
									    	$("#sendphoneButton").text("再次发送验证码");
									    } 
									} 
							,1000); //启动1秒定时 
						}else{
							$("#message").text(resultData.message);
					    	$('#sendphoneButton').removeAttr("disabled");
					    	$("#sendphoneButton").text("发送验证码");
						}
					},error:function(xhr){ alert('错误了\n\n'+xhr.responseText) }//回调看看是否有出错
				});
			}else{
				console.log("不能点");
			}
		}
	</script>
</@layout>